import type { CarouselProps } from 'antd';
import { Carousel as AntdCarousel } from 'antd';
import type { CarouselRef } from 'antd/lib/carousel';
import React, { useRef } from 'react';

export type { CarouselRef } from 'antd/lib/carousel';
export type Props = CarouselProps;

function Carousel(props: Props, ref: any) {
  const antdRef = useRef<CarouselRef>(null);

  React.useImperativeHandle(ref, () => ({
    goTo: antdRef.current?.goTo,
    autoPlay: antdRef.current?.innerSlider.autoPlay,
    innerSlider: antdRef.current?.innerSlider,
    prev: antdRef.current?.prev,
    next: antdRef.current?.next,
  }));
  return <AntdCarousel ref={antdRef} {...props} />;
}

export default React.forwardRef<CarouselRef, Props>(Carousel);
